﻿@model WebApp.Models.WaterManualReport
@{
  ViewData["Title"] = "水表月度汇总记录";
  ViewData["PageName"] = "WaterManualReports_Index";
  ViewData["Heading"] = "<i class='fal fa-window text-primary'></i>  水表月度汇总记录";
  ViewData["Category1"] = "收费管理";
  ViewData["PageDescription"] = "";
}
@section HeadBlock {
  <link href="@Fingerprint.Tag("/Scripts/plugin/jquery.fileuploader/jquery.fileuploader.min.css")" rel="stylesheet" />
  <link href="@Fingerprint.Tag("/Scripts/plugin/jquery.fileuploader/jquery.fileuploader-theme-dragdrop.css")" rel="stylesheet" />
  <link href="@Fingerprint.Tag("/Scripts/plugin/jquery.fileuploader/font/font-fileuploader.css")" rel="stylesheet" />
  <link href="@Fingerprint.Tag("/Content/css/notifications/toastr/toastr.css")" rel="stylesheet" />
  <link href="@Fingerprint.Tag("/Scripts/easyui/themes/insdep/easyui.css")" rel="stylesheet" />
  <link href="@Fingerprint.Tag("/Content/css/formplugins/bootstrap-daterangepicker/bootstrap-daterangepicker.css")" rel="stylesheet" />
}
<div class="row">
  <div class="col-lg-12 col-xl-12">
    <div id="panel-1" class="panel">
      <div class="panel-hdr">
        <h2>
          水表月度汇总记录
        </h2>
        <div class="panel-toolbar">
          <button class="btn btn-panel bg-transparent fs-xl w-auto h-auto rounded-0" data-action="panel-collapse" data-toggle="tooltip" data-offset="0,10" data-original-title="Collapse"><i class="fal fa-window-minimize"></i></button>
          <button class="btn btn-panel bg-transparent fs-xl w-auto h-auto rounded-0" data-action="panel-fullscreen" data-toggle="tooltip" data-offset="0,10" data-original-title="Fullscreen"><i class="fal fa-expand"></i></button>
          @*<button class="btn btn-panel bg-transparent fs-xl w-auto h-auto rounded-0" data-action="panel-close" data-toggle="tooltip" data-offset="0,10" data-original-title="Close"><i class="fal fa-trash-alt"></i></button>*@
        </div>

      </div>
      <div class="panel-container enable-loader show">
        <div class="loader"><i class="fal fa-spinner-third fa-spin-4x fs-xxl"></i></div>
        <div class="panel-content py-2 rounded-bottom border-faded border-left-0 border-right-0  text-muted bg-faded bg-subtlelight-fade">
          <div class="row no-gutters align-items-center">
            <div class="col">
              <!-- 开启授权控制请参考 @@if (Html.IsAuthorize("Create") -->
              <div class="btn-group btn-group-sm">
                <button name="searchbutton" class="btn btn-default"> <span class="fal fa-search mr-1"></span> @Html.L("Refresh") </button>
              </div>

              <div class="btn-group btn-group-sm">
                <button name="deleterowbutton" disabled class="btn btn-default"> <span class="fal fa-trash-alt mr-1"></span> @Html.L("Delete") </button>
              </div>

              <div class="btn-group btn-group-sm hidden-xs">
                <button name="importexcelbutton" type="button" class="btn btn-default"><span class="fal fa-cloud-upload mr-1"></span>导入抄表记录 </button>
                <button type="button" class="btn btn-default dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <span class="sr-only">Toggle Dropdown</span>
                </button>
                <div class="dropdown-menu">
                  <button name="downloadtemplatebutton" class="dropdown-item js-waves-on"><span class="fal fa-download"></span> 下载抄表模板 </button>
                </div>
              </div>
              <div class="btn-group btn-group-sm ">
                <button name="exportexcelbutton" class="btn btn-default"> <span class="fal fa-file-excel mr-1"></span>  @Html.L("Export") </button>
              </div>
              <div class="btn-group btn-group-sm ">
                <button name="helpbutton" class="btn btn-default"> <span class="fal fa-question-circle mr-1"></span> @Html.L("Help") </button>
              </div>
            </div>
          </div>
        </div>
        <div class="panel-content">
          <div class="table-responsive">
            <table id="watermanualreports_datagrid">
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

@section ScriptsBlock {
  @{ Html.RenderPartial("_ImportWindow", new ViewDataDictionary { { "EntityName", "WaterManualRecord" } }); }
  <script src="@Fingerprint.Tag("/Scripts/plugin/jquery.fileuploader/jquery.fileuploader.min.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/plugin/numeral/numeral.min.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/plugin/moment/moment-with-locales.min.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/notifications/toastr/toastr.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/formplugins/bootstrap-daterangepicker/bootstrap-daterangepicker.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/easyui/jquery.easyui.min.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/easyui/plugins/datagrid-filter.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/easyui/locale/easyui-lang-zh_CN.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/jquery.easyui.component.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/jquery.extend.formatter.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/jquery.custom.extend.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/plugin/jquery.serializejson/jquery.serializejson.min.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/plugin/filesaver/FileSaver.min.js")"></script>
  <script src="@Fingerprint.Tag("/Scripts/plugin/filesaver/jquery.fileDownload.js")"></script>
  <script type="text/javascript">
    //绑定按钮事件
    $('button[name="searchbutton"]').on('click', reloadData);
    $('button[name="appendbutton"]').on('click', appendData);
    $('button[name="deleterowbutton"]').on('click', deleteRow);
    $('button[name="exportexcelbutton"]').on('click', exportExcel);
    $('button[name="importexcelbutton"]').on('click', () => {
      importexcel('WaterManualRecord')
    });
    $('button[name="downloadtemplatebutton"]').on('click', () => {
      downloadtemplate()
    });
    //下载Excel导入模板
    function downloadtemplate() {
      //默认模板路径存放位置
      const url = '/WaterManualRecords/DownloadTemplate';
      $.fileDownload(url)
        .done(() => {
          //console.log('file download a success!');
          toastr.success('模板下载完成!');
        })
        .fail(() => {
          $.messager.alert('下载模板失败', '没有下载到导入模板!', 'error');
        });
    }
    //全屏事件
    document.addEventListener('panel.onfullscreen', () => {
         $dg.datagrid('resize');
     });
      //是否强制从后台取值
      const REQUIRBACKEND = false;
      //是否开启行内编辑
      const EDITINLINE = false;
      var watermanualreport = {};

       //执行导出下载Excel
       function exportExcel() {
                const filterRules = JSON.stringify($dg.datagrid('options').filterRules);
                //console.log(filterRules);
                const dialog = bootbox.dialog({
                    message: '<div class="text-center"><i class="fal fa-spinner fa-pulse fa-lg mr-1"></i> 正在执行...</div>',
                    closeButton: false
                 });
                let formData = new FormData();
                formData.append('filterRules', filterRules);
                formData.append('sort', 'Id');
                formData.append('order', 'asc');
                $.postDownload('/WaterManualReports/ExportExcel', formData).then(res => {
                    setTimeout(() => {
                       dialog.modal('hide')
                     }, 300);
                    toastr.success('导出成功!');
                }).catch(err => {
                    setTimeout(() => {
                       dialog.modal('hide')
                     }, 300);
                    $.messager.alert('导出失败', err.statusText, 'error');
                });

        }
        //显示帮助信息
        function dohelp() {
            toastr.info('有问题请联系管理员 <br><i class="fa fa-envelope-o" aria-hidden="true"></i> : demo@admin.com','帮助');
        }
    var editIndex = undefined;
    function reload() {
      reloadData();
    }
       //重新加载数据
       function reloadData() {
            $dg.datagrid('unselectAll');
            $dg.datagrid('uncheckAll');
            $dg.datagrid('reload');
       }
    //新增记录
    async function appendData() {
       watermanualreport = {  };
        //需要后台创建对象
       if (REQUIRBACKEND) {
         watermanualreport = await $.get('/WaterManualReports/NewItem');
       }
           //弹出新增窗口
           openwatermanualreportdetailwindow(watermanualreport, 'Added');
    }
    //删除编辑的行
    function deleteRow() {
    deleteChecked();
    }
    //删除选中的行
    function deleteChecked() {
        const checked = $dg.datagrid('getChecked').filter(item=>item.Id!=null && item.Id > 0).map(item => {
                   return item.Id;
                });;
        if (checked.length > 0) {
              deleteRows(checked);
         } else {
                $.messager.alert('提示', '请先选择要删除的记录!','question');
         }
     }
    //执行删除
    function deleteRows(selected){
      $.messager.confirm('确认', `你确定要删除这 <span class='badge badge-icon position-relative'>${selected.length} </span> 行记录?`, result => {
       if (result) {
         $.post('/WaterManualReports/DeleteChecked', { id: selected })
                         .done(response => {
                                if (response.success) {
                                    toastr.error(`成功删除 [${selected.length}] 行记录`);
                                    reloadData();
                                } else {
                                    $.messager.alert('错误', response.err,'error');
                                }
                          })
                          .fail((jqXHR, textStatus, errorThrown) => {
                             $.messager.alert('异常', `${jqXHR.status}: ${jqXHR.statusText} `, 'error');
                          });
        }
      });
    }
    //弹出明细信息
    async function showdetailsWindow(id,index) {
        const watermanualreport = $dg.datagrid('getRows')[index];
        if (REQUIRBACKEND) {
           watermanualreport = await $.get('/WaterManualReports/GetItem/' + id);
        }
        openwatermanualreportdetailwindow(watermanualreport,'Modified');
    }

    //初始化定义datagrid
    var $dg = $('#watermanualreports_datagrid');
    $(() => {
      //定义datagrid结构
      $dg.datagrid({
       height:670,
        pageSize:15,
        rownumbers: true,
        checkOnSelect: false,
        selectOnCheck: false,
        idField: 'Id',
        sortName: 'Id',
        sortOrder: 'desc',
        remoteFilter: true,
        singleSelect: true,
        //url: '/WaterManualReports/GetData',
        method: 'post',
        pagination: true,
        clientPaging: false,
        striped: true,
        pageList: [15, 20, 50, 100, 500, 2000],
        filterRules: [],
        onBeforeLoad: function () {
          $('.enable-loader').removeClass('enable-loader')
        },
        onLoadSuccess: function (data) {
          $("button[name*='deleterowbutton']").prop('disabled', true);
        },
        onCheck: function () {
          $("button[name*='deleterowbutton']").prop('disabled', false);
        },
        onUncheck: function () {
          const checked = $(this).datagrid('getChecked').length > 0;
          $("button[name*='deleterowbutton']").prop('disabled', !checked);
        },
        onCheckAll: function (rows) {
          if (rows.length > 0) {
            $("button[name*='deleterowbutton']").prop('disabled', false);
          }
        },
        onUncheckAll: function () {
          $("button[name*='deleterowbutton']").prop('disabled', true);
        },
        onSelect: function (index, row) {
          watermanualreport = row;
        },
        frozenColumns: [[
          /*开启CheckBox选择功能*/
          { field: 'ck', checkbox: true },

        ]],
        columns: [[
          {    /*表号*/
            field: 'Month',
            title: '@Html.DisplayNameFor(model => model.Month)',
            width: 120,
            hidden: false,
            sortable: true,
            resizable: true
          },
          {    /*表号*/
            field: 'meterId',
            title: '@Html.DisplayNameFor(model => model.meterId)',
            width: 120,
            hidden: false,
            sortable: true,
            resizable: true
          },
          {    /*meterType*/
            field: 'meterType',
            title: '@Html.DisplayNameFor(model => model.meterType)',
            width: 100,
            hidden: false,
            sortable: true,
            resizable: true
          },
          {    /*表名*/
            field: 'Name',
            title: '@Html.DisplayNameFor(model => model.Name)',
            width: 200,
            hidden: false,
            sortable: true,
            resizable: true
          },
          {    /*表序号*/
            field: 'LineNo',
            title: '@Html.DisplayNameFor(model => model.LineNo)',
            width: 200,
            hidden: false,
            sortable: true,
            resizable: true
          },
          {    /*出线名称*/
            field: 'Name1',
            title: '@Html.DisplayNameFor(model => model.Name1)',
            width: 200,
            hidden: false,
            sortable: true,
            resizable: true
          },

          {    /*上期读数*/
            field: 'LastWater',
            title: '@Html.DisplayNameFor(model => model.LastWater)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: numberformatter,
            sortable: true,
            resizable: true
          },
          {   /*上期抄表日期*/
            field: 'LastRecordDate',
            title: '@Html.DisplayNameFor(model => model.LastRecordDate)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: dateformatter,
            sortable: true,
            resizable: true
          },
           {    /*本期读数*/
            field: 'Water',
            title: '@Html.DisplayNameFor(model => model.Water)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: numberformatter,
            sortable: true,
            resizable: true
          },
          {   /*抄表日期*/
            field: 'RecordDate',
            title: '@Html.DisplayNameFor(model => model.RecordDate)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: dateformatter,
            sortable: true,
            resizable: true
          },
          {    /*本期用水量*/
            field: 'CalWater',
            title: '@Html.DisplayNameFor(model => model.CalWater)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: numberformatter,
            sortable: true,
            resizable: true
          },
          {    /*本期用水量*/
            field: 'LastRatio',
            title: '@Html.DisplayNameFor(model => model.LastRatio)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: function (v, row, i) {
              if (v != null) {
                const result = numeral(v).value();
                if (result > 0) {
                  return `<span class="badge badge-success">${result} % </span>`
                } else {
                  return `<span class="badge badge-danger">${result} % </span>`
                }
              } else {
                return '';
              }



            },
            sortable: true,
            resizable: true
          },
          {    /*本期用水量*/
            field: 'YearRatio',
             title: '@Html.DisplayNameFor(model => model.YearRatio)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: function (v, row, i) {
              if (v != null) {
                const result = numeral(v).value();
                if (result > 0) {
                  return `<span class="badge badge-success">${result} % </span>`
                } else {
                  return `<span class="badge badge-danger">${result} % </span>`
                }
              } else {
                return '';
              }

            },
            sortable: true,
            resizable: true
          },
          {    /*本期用水量*/
            field: 'LastCalWater',
            title: '@Html.DisplayNameFor(model => model.LastCalWater)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: numberformatter,
            sortable: true,
            resizable: true
          },
          {    /*本期用水量*/
            field: 'OnYearCalWater',
            title: '@Html.DisplayNameFor(model => model.OnYearCalWater)',
            width: 100,
            align: 'right',
            hidden: false,
            formatter: numberformatter,
            sortable: true,
            resizable: true
          },
          {    /*备注*/
            field: 'Remark',
            title: '@Html.DisplayNameFor(model => model.Remark)',
            width: 260,
            hidden: false,
            sortable: true,
            resizable: true
          },
        ]]
      }).datagrid('enableFilter', [
        {  /*状态*/
          field: 'Month',
          type: 'combobox',
          options: {
            url: '/WaterManualReports/GetMonthDataSource',
            panelHeight: 'auto',
            onChange: value => {
              if (value == '') {
                $dg.datagrid('removeFilterRule', 'Month');

              } else {
                $dg.datagrid('addFilterRule', {
                  field: 'Month',
                  op: 'equal',
                  value: value
                });

              }
              $dg.datagrid('doFilter');
              //
            }
          }
        },
        {   /*本期读数*/
          field: 'meterType',
          type: 'metertypefilter'
          
        },
        {   /*本期读数*/
          field: 'Water',
          type: 'numberbox',
          op: ['equal', 'notequal', 'less', 'lessorequal', 'greater', 'greaterorequal']
        },
        {   /*上期读数*/
          field: 'LastWater',
          type: 'numberbox',
          op: ['equal', 'notequal', 'less', 'lessorequal', 'greater', 'greaterorequal']
        },
        {   /*本期用水量*/
          field: 'CalWater',
          type: 'numberbox',
          op: ['equal', 'notequal', 'less', 'lessorequal', 'greater', 'greaterorequal']
        },
        {     /*抄表日期*/
          field: 'RecordDate',
          type: 'dateRange',
          options: {
          }
        },
        {     /*上期抄表日期*/
          field: 'LastRecordDate',
          type: 'dateRange',
          options: {
          }
        },
      ])
        .datagrid('load', '/WaterManualReports/GetData');

    });

  </script>



}


